// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

/// Filter pre-defined keywords from the received response.
///
/// Filter keywords that are either unique to each DUT (device ID) or alerts that
/// could misfire.
///
/// Arguments:
/// * response - The response received from the DUT.
pub fn filter_response_common(
    response: serde_json::Value,
) -> serde_json::Map<String, serde_json::Value> {
    let mut map: serde_json::Map<String, serde_json::Value> = response.as_object().unwrap().clone();
    // Depending on the device configuration, alerts can sometimes fire.
    map.remove("alerts");
    map.remove("ast_alerts");
    map.remove("err_status");
    // Device ID is different for each device.
    map.remove("device_id");
    // Filter the clock jitter enable/disable field as on A2 it is always enabled
    // when writing any value into the config register.
    map.remove("clock_jitter_en");
    // Remove device depenent configuration fields.
    map.remove("config_version");
    map.remove("sram_exec_mode");
    map.remove("ownership_key_alg");
    map.remove("update_mode");
    map.remove("min_security_version_bl0");
    map.remove("lock_constraint");
    map.remove("digest");
    map.remove("identifier");
    map.remove("scm_revision_low");
    map.remove("scm_revision_high");
    map.remove("rom_ext_slot");
    map.remove("rom_ext_major");
    map.remove("rom_ext_minor");
    map.remove("rom_ext_size");
    map.remove("bl0_slot");
    map.remove("ownership_state");
    map.remove("ownership_transfers");
    map.remove("rom_ext_min_sec_ver");
    map.remove("bl0_min_sec_ver");
    map.remove("primary_bl0_slot");
    map.remove("retention_ram_initialized");
    map.remove("bl0");
    map.remove("rom_ext");

    map
}
